package com.hksj.acm.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.hksj.acm.dto.DeviceCoreParamConfigSaveOrUpdateDTO;
import com.hksj.acm.service.DeviceCoreParamConfigService;
import com.hksj.acm.vo.DeviceCoreParamConfigVO;
import com.hksj.cbm.vo.DeriveMetadataVO;
import com.hksj.common.core.model.Rest;
import com.hksj.common.config.annotation.CurrentUserIdAndName;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author fjt
 * @data 2024/7/11 11:51
 * @describe todo
 */
@Api(tags = "空调机组-设备核心参数配置")
@RestController
@RequestMapping("/api/acm/deviceCoreParam")
public class DeviceCoreParamConfigController {

    @Autowired
    private DeviceCoreParamConfigService deviceCoreParamConfigService;


    @GetMapping("/list/{deviceId}")
    @ApiOperation(value = "查询指定设备的核心参数配置信息", notes = "查询指定设备的核心参数配置信息",response = DeviceCoreParamConfigVO.class)
    public Rest<List<DeviceCoreParamConfigVO>> queryDeviceCoreParamConfigByDeviceId(@PathVariable("deviceId") String deviceId){
        return Rest.ok(deviceCoreParamConfigService.queryDeviceCoreParamConfigByDeviceId(deviceId));
    }


    @CurrentUserIdAndName(id = "creator")
    @PostMapping("/save")
    @ApiOperation(value = "添加设备的核心参数配置", notes = "添加设备的核心参数配置")
    public Rest save(@RequestBody @Valid DeviceCoreParamConfigSaveOrUpdateDTO dto){
        String msg = deviceCoreParamConfigService.saveDeviceCoreParamConfig(dto);
        if (StringUtils.isNotBlank(msg)){
            return Rest.fail(msg);
        }
        return Rest.ok();
    }


    @GetMapping("/queryProperties/{deviceId}")
    @ApiOperation(value = "查询指定设备已经配置的物模型参数", notes = "查询指定设备已经配置的物模型参数",response = DeriveMetadataVO.class)
    public Rest<List<DeriveMetadataVO>> queryProperties(@PathVariable("deviceId") String deviceId){
        return Rest.ok(deviceCoreParamConfigService.queryProperties(deviceId));
    }


    @CurrentUserIdAndName(id = "updater")
    @PostMapping("/update")
    @ApiOperation(value = "更新设备的核心参数配置", notes = "更新设备的核心参数配置")
    public Rest update(@RequestBody @Valid DeviceCoreParamConfigSaveOrUpdateDTO dto){
        String msg = deviceCoreParamConfigService.updateDeviceCoreParamConfig(dto);
        if (StringUtils.isNotBlank(msg)){
            return Rest.fail(msg);
        }
        return Rest.ok();
    }


    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除设备的核心参数配置", notes = "删除设备的核心参数配置")
    public Rest delete(@PathVariable("id") Long id){
        Boolean bool = deviceCoreParamConfigService.removeById(id);
        if (bool){
            return Rest.ok();
        }
        return Rest.fail("删除失败");
    }


}
